#include "StompedReality/Core/Input/Windows/WGLMouseHandler.h"
#include <WindowsX.h>
#include <assert.h>
namespace StompedReality
{
namespace Input
{
WGLMouseHander::WGLMouseHander( )
  : MouseHandler( ), StompedReality::Core::SystemMessageListener( )
{
  this->m_NewMousePos.SetX( 0 );
  this->m_NewMousePos.SetY( 0 );
  this->m_UpdateMouse = 0;
  this->m_LeftMouseButton = 0;
  this->m_RightMouseMsg = 0;
}

WGLMouseHander::~WGLMouseHander( )
{
}

void WGLMouseHander::UpdateMouse( )
{
  if (m_UpdateMouse)
  {
    this->m_Mouse->UpdatePosition( &m_NewMousePos );

    //this->_mouse->updateButtons( &LeftMouseMsg, &RightMouseMsg );
    m_UpdateMouse = false;
  }
  else
  {
    this->m_Mouse->UpdatePosition( 0 );
  }
  this->m_Mouse->UpdateButtons( &m_LeftMouseButton, &m_RightMouseMsg );
  m_LeftMouseButton = 0;
  m_RightMouseMsg = 0;
}

void WGLMouseHander::ProcessMessage( StompedReality::Core::SystemMessage* msg )
{
  assert( msg != 0 );
  switch ( msg->message  )
  {
  case WM_MOUSEMOVE:
    m_NewMousePos.SetX((float)GET_X_LPARAM( msg->lParam ));
    m_NewMousePos.SetY((float)GET_Y_LPARAM( msg->lParam ));
    m_UpdateMouse = true;
    break;
  case WM_LBUTTONDOWN:
    m_LeftMouseButton = 1;
    break;
  case WM_LBUTTONUP:
    m_LeftMouseButton = 2;
    break;
  case WM_RBUTTONDOWN:
    m_RightMouseMsg = 1;
    break;
  case WM_RBUTTONUP:
    m_RightMouseMsg = 2;
    break;
  }
}

}
}